#include "Memento.h"
#include <iostream>

using namespace std;

Originator::Originator()
{
	_memento = 0;
}

Originator::~Originator()
{
	if (_memento)
	{
		delete _memento;
		_memento = 0;
	}
}

std::string Originator::GetState()
{
	return _state;
}

void Originator::SetState(std::string state)
{
	_state = state;
}

Memento* Originator::CreateMemento()
{
	if (_memento)
	{
		delete _memento;
		_memento = 0;
	}
	_memento = new Memento(_state);
	return _memento;
}
void Originator::SetMemento(Memento* memento)
{
	_state = memento->_state;
}

void Originator::Show()
{
	cout<<"State="<<_state<<endl;
}

Memento::Memento()
{

}

Memento::Memento(std::string state)
{
	_state = state;
}

Memento::~Memento()
{

}

std::string Memento::GetState()
{
	return _state;
}

Caretaker::Caretaker()
{
	_memento = 0;
}

Caretaker::~Caretaker()
{
	_memento = 0;
}

Memento* Caretaker::GetMemento()
{
	return _memento;
}

void Caretaker::SetMemento(Memento* memento)
{
	_memento = memento;
}